import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:jicaimao_flutter/utils/api_address.dart';
import 'package:jicaimao_flutter/utils/http_utils.dart';
import 'package:jicaimao_flutter/entity/mybox.dart';
import 'package:jicaimao_flutter/utils/sp_utils.dart';
import 'package:jicaimao_flutter/utils/sp_key.dart';

/**
 * 申购失败
 */
class SubscribePage extends StatefulWidget {

  @override
  State<StatefulWidget> createState() => new _SubscribePageState();
}

class _SubscribePageState extends State<SubscribePage> {

  var totolAcccout;
  var userAccout;
  var benAccout;

  @override
  void initState() {
    super.initState();
    _loadData();
  }
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return  new Scaffold(
      appBar: new AppBar(
          centerTitle: true,
          backgroundColor: Colors.white,
          elevation: 100.0,
          iconTheme: IconThemeData(
            color: Colors.black,
          ),
          title: new Text(
            '申购失败',
            style: new TextStyle(color: Colors.black),
          )
      ),
      body: new Container(
        child: Column(
          children: <Widget>[

            Container(
              color: Colors.white,
              alignment: Alignment.center,
              padding: EdgeInsets.all(15.0),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: new Column(
                      children: <Widget>[
                        Text('90天',style: TextStyle(
                            color: Colors.black,
                            fontSize: 16.0
                        ),),
                        Text('定期',style: TextStyle(
                            color: Colors.black,
                            fontSize: 16.0
                        ),),
                      ],
                      crossAxisAlignment: CrossAxisAlignment.start,
                    ),
                    flex: 1,),

                ],
              ),
            ),

            Container(
              color: Colors.white,
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.all(15.0),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: new Column(
                      children: <Widget>[
                        Text('积分数量（BSC）',style: TextStyle(
                            color: Colors.black,
                            fontSize: 16.0
                        ),),
                      ],
                      crossAxisAlignment: CrossAxisAlignment.start,
                    ),
                    flex: 1,),
                  Text("2000",style: TextStyle(
                      color: Colors.black,
                      fontSize: 15.0
                  ),)
                ],
              ),
            ),

            Container(
              color: Colors.white,
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.all(15.0),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: new Column(
                      children: <Widget>[
                        Text('申购时间',style: TextStyle(
                            color: Colors.black,
                            fontSize: 16.0
                        ),),
                      ],
                      crossAxisAlignment: CrossAxisAlignment.start,
                    ),
                    flex: 1,),
                  Text("2019-1-23 15:12:30",style: TextStyle(
                      color: Colors.black,
                      fontSize: 15.0
                  ),)
                ],
              ),
            ),

            Container(
              color: Colors.white,
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.all(15.0),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: new Column(
                      children: <Widget>[
                        Text('BSC钱包地址',style: TextStyle(
                            color: Colors.black,
                            fontSize: 16.0
                        ),),
                      ],
                      crossAxisAlignment: CrossAxisAlignment.start,
                    ),
                    flex: 1,),
                  Text("Asaadasdasdasdas",style: TextStyle(
                      color: Colors.black,
                      fontSize: 15.0
                  ),)
                ],
              ),
            ),

          ],
        ),
      ),
    );

  }

  void _loadData() async {
    String url = NetAddress.myBoxList;
    String userId = SpUtils.getString(SpKey.KEY_USER_ID);
    print("key=${userId}");
    var data = {'userId': userId};
    var respone = await HttpUtil().post(url,data: data);
    setState(() {
      mybox _mybox = mybox.fromJson(json.decode(respone));
      if(_mybox.code == "200"){
        totolAcccout = _mybox.result.sum;
        userAccout = _mybox.result.available;
        benAccout = _mybox.result.financial;
        print(_mybox.result.available);
      }else{
        print(_mybox.msg);
      }
    });
  }

}
